import axios from 'axios';
import qs from 'query-string';

export interface MenuId {
    id: number;
}

export interface MenuRecord {
    id: number;
    name: string;
    description: string;
    image: string;
    image_url: string;
    path: string;
    created_at: string;
    updated_at: string;
}

export interface MenuListRes {
    list: MenuRecord[];
    total: number;
}

export interface MenuModel {
    id: number;
    name: string;
    description: string;
    image: string;
    path: string;
}

export interface MenuParams extends Partial<MenuRecord> {
    page: number;
    pageSize: number;
}

/**
 * 获取菜单列表
 * @param params
 */
export function queryMenuList(params: MenuParams) {
    return axios.get<MenuListRes>('/admin/menu/index', {
        params,
        paramsSerializer: (obj) => {
            return qs.stringify(obj);
        },
    });
}

/**
 * 获取菜单详情
 * @param params
 */
export function queryMenuOne(params: MenuId) {
    return axios.get<MenuRecord>('/admin/menu/detail', {
        params,
        paramsSerializer: (obj) => {
            return qs.stringify(obj);
        },
    });
}

/**
 * 提交菜单表单（创建/更新）
 * @param data
 */
export function submitMenuForm(data: any) {
    return axios.post('/admin/menu/submit', data);
}

/**
 * 删除菜单
 * @param id
 */
export function delMenu(id: number) {
    return axios.post('/admin/menu/delete', { id });
} 